package thread.thread016;

import java.util.concurrent.Callable;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.FutureTask;

/**
 * @program: baseModule
 * @description:
 * @author: zhanghz001
 * @create: 2020-10-26 03:22
 **/
public class ProviderRun implements Runnable {
    @Override
    public void run() {
        while (true) {
            synchronized (StatusTest.lock) {
                StatusTest.lock.notifyAll();

                System.out.println("消费进入wait状态");
                //
                try {
                    StatusTest.lock.wait();
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
                //
                Callable<String> callable = new Callable<>() {
                    @Override
                    public String call() throws Exception {
                        try {
                            Thread.sleep(1000);
                        } catch (InterruptedException e) {
                            e.printStackTrace();
                        }
                        return null;
                    }
                };
                FutureTask<String> task = new FutureTask<>(callable);
                new Thread(task).start();
                try {
                    task.get();
                } catch (InterruptedException e) {
                    e.printStackTrace();
                } catch (ExecutionException e) {
                    e.printStackTrace();
                }

                System.out.println("消费执行完成了");
            }
        }
    }
}
